mui.init();
/*
 phone手机号,guideId所在群导购ID,targetId目标群组ID,db创建websql
 * */
var phone = readData(localStorage.phone);
var guideId = readData(localStorage.guideId);
var targetId = readData(localStorage.groupId);
var db = openDatabase('messageChat', '1.0', 'messageChatOfHistory DB', 4 * 1024 * 1024);
var demo = new Vue({
	el: '#main',
	data: {
		userlists: []
	},
	methods: {
		opennewwin: opennewwin,
		clearGroup: clearGroup
	},
	ready: function() {
		var urlFriend = getUrl("48circleMember");
		var headerFriend = getHeader();
		var guideId = readData(localStorage.guideId);
		datas = "userId=" + guideId;
		this.$http({
			url: urlFriend,
			method: 'POST',
			headers: headerFriend,
			data: datas,
			timeout: 10000
		}).then(function(respons) {
			if (respons.data.obj) {
				//圈子列表成员信息					
				var userlist = respons.data.obj.list;
				console.log(JSON.stringify(userlist))
				for (i = 0; i < userlist.length; i++) {
					if (!userlist[i]["nickname"]) {
						userlist[i]["nickname"] = "匿名";
					}
					if (!userlist[i]["headimg"] || userlist[i]["headimg"] == "null") {
						userlist[i]["headimg"] = "../../image/share/pl_tp.png";
					}
				}
				this.$set('userlists', userlist);
			}
		}, function() {
			console.log('圈子列表成员信息出错');
		});
	}
});

function opennewwin(num, userType, huanxinid) {
	localStorage.accountnum = writeData(num);
	localStorage.usertype = writeData(userType);
	mui.openWindow({
		url: "friendDetail.html",
		id: 'friendDetail.html',
		waiting: {
			autoShow: false
		}
	});
}

//清除群消息记录
function clearGroup() {
	var btnArray = ['否', '是'];
	mui.confirm('你确认要清除群历史消息?', '提示', btnArray, function(e) {
		if (e.index == 1) {
			db.transaction(function(tx) {
				tx.executeSql('DELETE FROM MessageHistory  WHERE Id=? AND Phone=? AND GuideId=?', [targetId, phone, guideId]);
			    mui.toast('清除历史消息成功')
			})
		} 
	})
}
